aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/groups/[groupId]/layout.tsx
blob: cb31df740980e0fc6d9d2f65a86ab7ca65b4ece5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { cached } from '@/app/cached-functions'
import { GroupTabs } from '@/app/groups/[groupId]/group-tabs'
import { SaveGroupLocally } from '@/app/groups/[groupId]/save-recent-group'
import { ShareButton } from '@/app/groups/[groupId]/share-button'
import { Metadata } from 'next'
import Link from 'next/link'
import { notFound } from 'next/navigation'
import { PropsWithChildren, Suspense } from 'react'

type Props = {
  params: {
    groupId: string
  }
}

export async function generateMetadata({
  params: { groupId },
}: Props): Promise<Metadata> {
  const group = await cached.getGroup(groupId)

  return {
    title: {
      default: group?.name ?? '',
      template: `%s · ${group?.name} · Spliit`,
    },
  }
}

export default async function GroupLayout({
  children,
  params: { groupId },
}: PropsWithChildren<Props>) {
  const group = await cached.getGroup(groupId)
  if (!group) notFound()

  return (
    <>
      <div className="flex flex-col sm:flex-row justify-between sm:items-center gap-3">
        <h1 className="font-bold text-2xl">
          <Link href={`/groups/${groupId}`}>{group.name}</Link>
        </h1>

        <div className="flex gap-2 justify-between">
          <Suspense>
            <GroupTabs groupId={groupId} />
          </Suspense>
          <ShareButton group={group} />
        </div>
      </div>

      {children}

      <SaveGroupLocally group={{ id: group.id, name: group.name }} />
    </>
  )
}